package org.example.y24.m11;

public class BinarySearch {
    public static int getPos(int[] A, int n, int val) {
        int l = 0, r = n - 1;

        while (l <= r) {
            int mid = l + (r - l) / 2;

            if (A[mid] == val) {
                return 1;
            } else if (A[mid] < val) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }

        return -1;
    }

    public static void main(String[] args) {
        int[] A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        System.out.println(getPos(A, 10, 9));
    }
}
